<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('commerce_order_product', function (Blueprint $table) {
            $table->comment('订单商品');
            $table->unsignedBigInteger('order_id')->comment('订单号');
            $table->unsignedBigInteger('commodity_id')->comment('商品ID');
            $table->string('commodity_name', 255)->comment('商品名称');
            $table->integer('quantity')->comment('数量');
            $table->decimal('price', 10, 2)->comment('单价');
            $table->decimal('discount', 10, 2)->comment('折扣');
            $table->decimal('reduction', 10, 2)->comment('满减');
            $table->decimal('total_price', 10, 2)->comment('总价');
            $table->json('photo')->nullable()->comment('图片');
            $table->json('commodity_spec')->nullable()->comment('商品规格');
            $table->string('commodity_unit', 8)->nullable()->comment('商品单位');
            $table->timestamps();
            $table->primary(['order_id', 'commodity_id']);
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('commerce_order_product');
    }
};